package com.example.jixeishi1.controller;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
import com.example.jixeishi1.dao.HRSShangPindao;
import com.example.jixeishi1.entity.*;
import com.example.jixeishi1.service.HRSShangPinService;
import com.example.jixeishi1.service.lmpi.AlipayServiceImpl;
import com.example.jixeishi1.util.OrderUtil;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@CrossOrigin
@Controller
public class HRSZhuycontroller {
    @Autowired
    HRSShangPinService hrsShangPinService;
    @Autowired
    AlipayServiceImpl alipayServicei;
    @Autowired
    HRSShangPindao hrsShangPindao;
    @GetMapping("/fen3")
    public  String fen2(ModelMap map){
        System.out.println("1212");
        List list=hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1",list);

        map.put("ints1",1);
        return "hrszhuyei";
    }

    @GetMapping("/fen4")
    public  String fen3(ModelMap map) {
        List list = hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1", list);

        return "hrsGeirnzj";
    }
    @GetMapping("/fen5")
    public  String fen4(int id,ModelMap map){
        System.out.println(id);
        List list=hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1",list);
        List list2=hrsShangPinService.getListuser(id);
        map.put("ints1",list2);
        List listq1 =hrsShangPinService.getListhuanying(id);
        map.put("intshuanying",listq1);
        List listGR =hrsShangPinService.getLisjixeishigrxx(id);

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//       List data = (List) listGR.u

        map.put("intGR",listGR);
        System.out.println(listGR);
        return "hrsGeirnzj";
    }
    @GetMapping("/fen6")
    public  String fen5(int id,ModelMap map){
        System.out.println(id);
        List list=hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1",list);
        List list2=hrsShangPinService.getListuser(id);
        map.put("ints1",list2);
        System.out.println(list2);

        return "hrszhuyei";
    }
    @GetMapping("/upload1")
    public Object upload(){
        System.out.println(1231231231);

        return "dl";
    }
    @GetMapping("/")
    public String uploladPage(){
        return "upload";
    }
    @PostMapping("/upload")
    public String fileUpload(
            @RequestParam("file") MultipartFile file, HttpServletRequest req, Model model, GeRen geRen,ModelMap map,int id){
        try {
            String fileName = file.getOriginalFilename();
            String destFileName="W:\\HB\\boot1\\JiXeiShi1\\target\\classes\\static\\img\\JiXeiShu"+ File.separator+fileName;
            System.out.println(destFileName);
            System.out.println(destFileName);
            File destFile = new File(destFileName);
            destFile.getParentFile().mkdirs();
            System.out.println(destFile);
            file.transferTo(destFile);
            System.out.println("-----"+geRen.getTouxiang());
            geRen.setZhenshixingm(null);
            geRen.setTouxiang(fileName);
            geRen.setChushengriqi(null);
            geRen.setXingb(null);
            geRen.setSzd(null);
            geRen.setQQ(null);
            System.out.println("-----"+id);
            geRen.setYhid(id);
int sy=hrsShangPinService.getproductupdate(geRen);
            model.addAttribute("fileName",fileName);
            model.addAttribute("path",destFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return "上传失败," + e.getMessage();
        } catch (IOException e) {
            e.printStackTrace();
            return "上传失败," + e.getMessage();
        }
        System.out.println(id);
        List list=hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1",list);
        List list2=hrsShangPinService.getListuser(id);
        map.put("ints1",list2);
        List listq1 =hrsShangPinService.getListhuanying(id);
        map.put("intshuanying",listq1);
        List listGR =hrsShangPinService.getLisjixeishigrxx(id);

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//       List data = (List) listGR.u

        map.put("intGR",listGR);
        System.out.println(listGR);

        return "hrsGeirnzj";
    }
    @PostMapping("/fen7")
    public  String fen6(int yhid, ModelMap map,GeRen geRen){

        System.out.println(geRen.getZhenshixingm());
        System.out.println(geRen.getChushengriqi());
        System.out.println(geRen.getXingb());
        System.out.println(geRen.getSzd());

         geRen.setZhenshixingm(geRen.getZhenshixingm());

            geRen.setTouxiang(null);
            geRen.setChushengriqi(geRen.getChushengriqi());
            geRen.setXingb(geRen.getXingb());
            geRen.setSzd(geRen.getSzd());
            geRen.setQQ(geRen.getQQ());
            System.out.println("-----"+yhid);
            geRen.setYhid(yhid);
int sy=hrsShangPinService.getproductupdate(geRen);

        System.out.println(yhid);
        List list=hrsShangPinService.getList();
        System.out.println(list);
        map.put("int1",list);
        List list2=hrsShangPinService.getListuser(yhid);
        map.put("ints1",list2);
        List listq1 =hrsShangPinService.getListhuanying(yhid);
        map.put("intshuanying",listq1);
        List listGR =hrsShangPinService.getLisjixeishigrxx(yhid);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//       List data = (List) listGR.u

        map.put("intGR",listGR);
        System.out.println(listGR);


        return "hrsGeirnzj";
    }
    @PostMapping("/fen8")
    public  String fen7(@RequestBody User user){
        System.out.println(user);
        user.setPassword(user.getPassword());
        user.setId(user.getId());
        System.out.println();

        int xgmm1 =hrsShangPinService.xgmmtupdate(user);


        return "hrsGeirnzj";
    }
    @GetMapping ("/fen9")
    public  String fen8(){
        return "dl";
    }

    @RequestMapping ("/fen11")
    @ResponseBody
    public JsonResult1 fen11(@RequestBody Dizhi dizhi, ModelMap map){
        System.out.println(123123);
        int DZ =hrsShangPinService.Dizhi(dizhi);
        System.out.println(DZ+""+dizhi.getUserid());
      List  dz2=hrsShangPinService.dz2(dizhi.getUserid());

        System.out.println("11111---"+dz2);
        map.put("dz2",dz2);
JsonResult1 st=new JsonResult1(200,"",dz2);
        return st;

    }
    @RequestMapping ("/fen12")
    public String fen12(String uid, String dzid, ModelMap map, HttpSession se){
        ServletContext app=    se.getServletContext();
        System.out.println(uid);
       int dzid1=Integer.parseInt(dzid);
        int uid1=Integer.parseInt(uid);
        int DZ =hrsShangPinService.deleteDizhi(dzid1);
//        System.out.println(DZ+""+dizhi.getUserid());
        List  dz2=hrsShangPinService.dz2(uid1);

        System.out.println(uid);
        List list=hrsShangPinService.getList();
        System.out.println(list);
//        map.put("int1",list);
        app.setAttribute("int1",list);
        List list2=hrsShangPinService.getListuser(uid1);
//        map.put("ints1",list2);
        app.setAttribute("ints1",list2);
        List listq1 =hrsShangPinService.getListhuanying(uid1);
//        map.put("intshuanying",listq1);
        app.setAttribute("intshuanying",listq1);
        List listGR =hrsShangPinService.getLisjixeishigrxx(uid1);

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

//       List data = (List) listGR.u

//        map.put("intGR",listGR);
        app.setAttribute("intGR",listGR);
        System.out.println(listGR);
        return "hrsGeirnzj";

    }
}
